<template>
  <div>
    <!-- <el-button type="text" @click="dialogFormVisible = true">打开嵌套表单的 Dialog</el-button> -->
    <el-dialog title="角色添加" :visible.sync="oppens.ones">
         {{form}}
      <el-form :model="form">
        <el-form-item label="角色名称" :label-width="formLabelWidth">
          <el-input v-model="form.rolename" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="角色权限" :label-width="formLabelWidth">
          <el-tree
            :data="infolist"
            show-checkbox
            default-expand-all
            node-key="id"
            ref="tree"
            highlight-current
            :props="defaultProps"
            @check="getCheckedKeys"
          >
          </el-tree>
        </el-form-item>
        <el-form-item label="角色状态">
          <el-switch
            v-model="form.status"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="2"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="oppens.ones = false">取 消</el-button>
        <el-button type="primary" @click="submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ["oppens"],
  data() {
    return {
      // dialogTableVisible: false,
      // dialogFormVisible: false,
      form: {
        rolename: "",
        menus: "",
        status: 1,
        
      },
      amenus:[],
      formLabelWidth: "120px",
      infolist: [],
      defaultProps: {
        children: "children",
        label: "title",
      },
    };
  },
  methods: {
    submit() {
      console.log(this.form);
      this.$api.reqRoleadd(this.form).then((res) => {
        console.log(res);
        this.oppens.ones = false;-
        this.$message({
          message: "角色添加成功",
          type: "success",
        });
        // this.$router.go(0)
      });
    },
    getCheckedKeys() {
      // console.log(this.$refs.tree.getCheckedKeys().join(','));
      this.form.menus = this.$refs.tree.getCheckedKeys().join(',');
    },
  },
  created() {},
  mounted() {
   this.$BUS.$on('deit',row=>{
     console.log(row);
     this.form=JSON.parse(JSON.stringify(row))
     this.oppens.off=true
   })
    this.$api.reqgoods({ istree: true }).then((res) => {
      console.log(res);
      this.infolist = res.data.list;
    });
  },
  components: {},
  computed: {},
  watch: {},
};
</script>

<style lang='scss' scoped>
</style>
